﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MyRabbit.Application.Command;
using MyRabbit.Application.Dtos;
using MyRabbit.Application.ErrorCode;
using MyRabbit.Domain;

namespace MyRabbit.Web.Api.Controllers
{
    /// <summary>
    /// 产品控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public ProductController(IMediator mediator)
        {
            this.mediator = mediator;
        }

       

        /// <summary>
        /// 添加产品
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> AddProduct(ProductAddCommand command)
        {
            return await mediator.Send(command);
        }


        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> DelProduct(ProductDelCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> UpdateProudct(ProductUpdateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 显示产品
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Product>>> ProductQuery()
        {
            ProductQueryCommand command = new ProductQueryCommand();
            return await mediator.Send(command);
        }
    }
}
